﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AnimaGestionPersonnage.Utilities
{
    /// <summary>
    /// Structure pour le stockage d'un module de combat
    /// </summary>
    public class CombatModule : IEquatable<CombatModule>, IComparer<CombatModule>, IComparable<CombatModule>
    {
        public string name { get; set; }
        public string description { get; set; }
        public TypeSkill type { get; set; }
        public bool canBeMultiple { get; set; }
        public int cost { get; set; }


        public CombatModule()
        {
        }

        public CombatModule(string n)
        {
            this.name = n;
        }

        public override string ToString()
        {
            return this.name;
        }

        public bool Equals(CombatModule ohterModule)
        {
            return name.Equals(ohterModule.name);
        }

        /// <summary>
        /// Compare 2 module et les place dans l'ordre suivant:
        /// 1 - Alphabetique
        /// </summary>
        /// <param name="thisModule"></param>
        /// <param name="otherModule"></param>
        /// <returns>la valeur position std des Compare(x,y)</returns>
        public int Compare(CombatModule thisModule, CombatModule otherModule)
        {
            int tempRet = 0;

            tempRet = thisModule.name.CompareTo(otherModule.name);

            return tempRet;
        }

        public int CompareTo(CombatModule other)
        {
            return this.Compare(this, other);
        }
    }

    public class GeneralModule : CombatModule, IEquatable<GeneralModule>, IComparer<GeneralModule>, IComparable<GeneralModule>
    {
        public Weapon weapon { get; set; }
        public WeaponRelations relation { get; set; }

        public GeneralModule()
        {
            canBeMultiple = false;
            type = TypeSkill.Combat;
        }

        public GeneralModule(Weapon w, WeaponRelations r)
            : this()
        {
            this.weapon = w;
            this.name = w.name;
            this.relation = r;

            switch (this.relation)
            {
                case WeaponRelations.Distincte:
                    this.cost = 20;
                    break;
                case WeaponRelations.Mixte:
                    this.cost = 15;
                    break;
                case WeaponRelations.Similaire:
                    this.cost = 10;
                    break;
                default:
                    throw new Exception();

            }
        }

        public bool Equals(GeneralModule otherModule)
        {
            return weapon.Equals(otherModule.weapon) && this.relation == otherModule.relation;
        }

        /// <summary>
        /// Compare 2 modules et les place dans l'ordre suivant:
        /// 1 - Alphabetique
        /// 2 - Relation
        /// </summary>
        /// <param name="thisModule"></param>
        /// <param name="otherSkill"></param>
        /// <returns>la valeur position std des Compare(x,y)</returns>
        public int Compare(GeneralModule thisModule, GeneralModule otherModule)
        {
            int tempRet = 0;

            tempRet = thisModule.name.CompareTo(otherModule.name) * 10;
            tempRet = (int)thisModule.relation - (int)otherModule.relation;

            return tempRet;
        }

        public int CompareTo(GeneralModule other)
        {
            return this.Compare(this, other);
        }
    }

    public class TypicalModule : CombatModule, IEquatable<TypicalModule>, IComparer<TypicalModule>, IComparable<TypicalModule>
    {
        public List<Weapon> weaponList { get; set; }

        public TypicalModule()
        {
            weaponList = new List<Weapon>();
            canBeMultiple = false;
            type = TypeSkill.Combat;
        }

        public TypicalModule(string n)
            : this()
        {
            this.name = n;
        }

        public bool Equals(TypicalModule otherModule)
        {
            return name.Equals(otherModule.name);
        }

        /// <summary>
        /// Compare 2 modules et les place dans l'ordre suivant:
        /// 1 - Alphabetique
        /// </summary>
        /// <param name="thisModule"></param>
        /// <param name="otherSkill"></param>
        /// <returns>la valeur position std des Compare(x,y)</returns>
        public int Compare(TypicalModule thisModule, TypicalModule otherModule)
        {
            int tempRet = 0;

            tempRet = thisModule.name.CompareTo(otherModule.name);

            return tempRet;
        }

        public int CompareTo(TypicalModule other)
        {
            return this.Compare(this, other);
        }
    }
}
